// 整个koa项目的入口
const Koa = require("koa");

const app = new Koa();
//端口号
const { port } = require("./config/config.default");

//! 允许跨域  npm i koa2-cors
const cors = require("koa2-cors");

const router = require("./router/index");

//todo 后端允许跨域
app.use(cors());

//* use()就是调用中间件
//! router.routes()的作用是：启动路由
//! router.alloweMethods()的作用是：允许任何请求(get,post,delete,put)
app.use(router.routes(), router.allowedMethods());

app.listen(port, () => {
  console.log(`Server is running in http://localhost:${port}`);
});
